# _*_ coding: UTF-8 _*_
# @Time     : 2021/10/29 17:16
# @Author   : Gong Yangyi
# @Site     : http://www.hzdledu.cn/
# @File     : prac.py
# @Software : PyCharm
from selenium import webdriver
import time
from selenium.webdriver.common.by import By

# 以百度首页为例，练习使用8种定位方式定位其中的元素
# 元素	1.id	2.name	3.link	4.partial link text	5.class name	6.tag name 	7.css selector	8.xpath
# 新闻			新闻	新	c-font-normal	a	#s-top-left > a:nth-child(1)	//*[@class="s-top-left s-isindex-wrap"]/a[1]
# hao123			hao123	hao	c-font-normal	a	#s-top-left > a:nth-child(2)	//*[@class="s-top-left s-isindex-wrap"]/a[2]
# 地图			地图	图	c-font-normal	a	#s-top-left > a:nth-child(3)	//*[@class="s-top-left s-isindex-wrap"]/a[3]
# 直播			直播	播	c-font-normal	a	#s-top-left > a:nth-child(4)	//*[@class="s-top-left s-isindex-wrap"]/a[4]
# 视频			视频	视	c-font-normal	a	#s-top-left > a:nth-child(5)	//*[@class="s-top-left s-isindex-wrap"]/a[5]
# 贴吧			贴吧	贴	c-font-normal	a	#s-top-left > a:nth-child(6)	//*[@class="s-top-left s-isindex-wrap"]/a[6]
# 学术			学术	学	c-font-normal	a	#s-top-left > a:nth-child(7)	//*[@class="s-top-left s-isindex-wrap"]/a[7]
# 更多			更多	更	c-font-normal	a	#s-top-left > a:nth-child(8)	//*[@class="s-top-left s-isindex-wrap"]/a[8]
# 设置					s-top-right-text	span	#s-usersetting-top	//*[@id="u1"]/span[1]
# 登录	s-top-loginbtn	tj_login	登录	登	s-top-login-btn	a	#s-top-loginbtn	//*[@id="u1"]/a[1]
# 百度图标	lg				s-p-top	area	#lg > map > area	//*[id="lg"]/map/area
# 输入框	kw	wd			s-ipt		#kw	//*[id="kw"]
# 按图片搜索					soutu-btn	span	#form > span.bg.s_ipt_wr.new-pmd.quickdelete-wrap > span.soutu-btn	//*[@id="form"]/span[1]/span[1]
# 百度一下	su				bg 	from	#su	//*[@id="su"]
# 关于百度			关于百度	关于	text-color	a	#bottom_layer > div > p:nth-child(1) > a	//*[@class="s-bottom-layer s-isindex-wrap"]/div/p[1]/a
# About Baidu			About Baidu	About	text-color	a	#bottom_layer > div > p:nth-child(2) > a	//*[@id="bottom_layer"]/div/p[2]/a
# 使用百度前必读			使用百度前必读	使用百度	text-color	a	#bottom_layer > div > p:nth-child(3) > a	//*[@id="bottom_layer"]/div/p[3]/a
# 帮助中心			帮助中心	帮助	text-color	a	#bottom_layer > div > p:nth-child(4) > a	//*[@id="bottom_layer"]/div/p[4]/a
# 京公网安备11000002000001号			京公网安备11000002000001号	京公网安备	text-color	a	#bottom_layer > div > p:nth-child(5) > a	//*[@id="bottom_layer"]/div/p[5]/a
# 京ICP证030173号			京ICP证030173号	京ICP	text-color	a	#bottom_layer > div > p:nth-child(6) > a	//*[@id="bottom_layer"]/div/p[6]/a
# ©2021 Baidu 			©2021 Baidu 	©2021	text-color	a	#bottom_layer > div > p:nth-child(7) > a	//*[@id="bottom_layer"]/div/p[7]/a
# 互联网药品信息服务资格证书 (京)-经营性-2017-0020			互联网药品信息服务资格证书 (京)-经营性-2017-0020	互联网药品信息	text-color	a	#bottom_layer > div > p:nth-child(8) > a	//*[@id="bottom_layer"]/div/p[8]/a
# 信息网络传播视听节目许可证 0110516			信息网络传播视听节目许可证 0110516	信息网络	text-color	a	#bottom_layer > div > p:nth-child(9) > a	//*[@id="bottom_layer"]/div/p[9]/a

# 将以上所有元素全部点击一遍
from selenium import webdriver
import time
from selenium.webdriver.common.by import By


def foo0():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('新闻').click()
    time.sleep(2)

    driver.quit()


def foo1():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_partial_link_text("hao").click()
    time.sleep(4)

    driver.quit()


def foo2():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#s-top-left > a:nth-child(3)').click()

    time.sleep(5)

    driver.quit()


def foo3():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_xpath('//*[@class="s-top-left s-isindex-wrap"]/a[4]').click()

    time.sleep(10)

    driver.quit()


def foo4():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    elements = driver.find_elements_by_class_name("c-font-normal")
    for element in elements:
        print(element.text)
    time.sleep(2)

    driver.quit()


def foo5():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_xpath('//*[@class="s-top-left s-isindex-wrap"]/a[5]').click()

    time.sleep(10)

    driver.quit()


def foo6():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('视频').click()  # 模拟鼠标左键单击
    time.sleep(2)

    driver.quit()


def foo7():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_partial_link_text("贴").click()  # 模拟鼠标左键单击
    time.sleep(4)

    driver.quit()


def foo8():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#s-top-left > a:nth-child(7)').click()

    time.sleep(5)

    driver.quit()


def foo9():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('更多').click()  # 模拟鼠标左键单击
    time.sleep(2)

    driver.quit()


def foo10():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    elements = driver.find_elements_by_class_name("s-top-right-text")  # 获取所有class属性为mnav的元素的列表
    for element in elements:
        print(element.text)  # 获取元素text
    time.sleep(2)

    driver.quit()


def foo11():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    # 找单个元素
    element = driver.find_element_by_name('tj_login').click()
    time.sleep(2)

    driver.quit()


def foo12():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')
    element = driver.find_element_by_id('lg').click()  # 通过id定位搜索输入框
    time.sleep(2)

    driver.quit()


def foo13():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#lg > map > area').click()

    time.sleep(5)

    driver.quit()


def foo14():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#form > span.bg.s_ipt_wr.new-pmd.quickdelete-wrap > span.soutu-btn').click()

    time.sleep(5)

    driver.quit()


def foo15():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_xpath('//*[@id="su"]').click()

    time.sleep(2)

    driver.quit()


def foo16():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('关于百度').click()
    time.sleep(2)

    driver.quit()


def foo17():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('About Baidu').click()
    time.sleep(2)

    driver.quit()


def foo18():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('使用百度前必读').click()
    time.sleep(2)

    driver.quit()


def foo19():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_link_text('帮助中心').click()
    time.sleep(2)

    driver.quit()


def foo20():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#bottom_layer > div > p:nth-child(5) > a').click()

    time.sleep(2)

    driver.quit()


def foo21():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#bottom_layer > div > p:nth-child(6) > a').click()

    time.sleep(2)

    driver.quit()


def foo22():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#bottom_layer > div > p:nth-child(7) > a').click()

    time.sleep(2)

    driver.quit()


def foo23():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_css_selector('#bottom_layer > div > p:nth-child(8) > a').click()

    time.sleep(2)

    driver.quit()


def foo24():
    driver = webdriver.Chrome()
    driver.maximize_window()

    driver.get('https://www.baidu.com/')

    driver.find_element_by_xpath('//*[@id="bottom_layer"]/div/p[9]/a').click()

    time.sleep(2)

    driver.quit()


if __name__ == '__main__':
    # foo0()
    # foo1()
    # foo2()
    # foo3()
    # foo4()
    # foo5()
    # foo6()
    # foo7()
    # foo8()
    # foo9()
    # foo10()
    # foo11()
    # foo12()
    # foo13()
    # foo14()
    # foo15()
    # foo16()
    # foo17()
    # foo18()
    # foo19()
    # foo20()
    # foo21()
    # foo22()
    # foo23()
    foo24()
